package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IEditUserInfoView
import de.baumann.browser.model.UserModel
import de.baumann.browser.utils.getUser
import de.baumann.browser.utils.updateQQ
import de.baumann.browser.utils.updateUserETHUrl
import de.baumann.browser.utils.updateUserName

class EditUserInfoPresenter : BasePresenter<IEditUserInfoView>() {
    private val userModel = UserModel()

    fun editEthUrl(address:String) {
        this.userModel.editEthUrl(address)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        updateUserETHUrl(view.content)
                        if (view != null)
                            view.editSuccess()
                    }
                })
    }


    fun editNickname() {
        this.userModel.editNickname(view.content)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        updateUserName(view.content)
                        if (view != null)
                            view.editSuccess()
                    }
                })
    }

    fun editQQ() {
        this.userModel.editQQ(view.content)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        updateQQ(view.content)
                        if (view != null)
                            view.editSuccess()
                    }
                })
    }

}